// Metgine/Core/Camera.h
//
// Copyright 2011 Phillip Stephens
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// Linking this library statically or dynamically with other modules is
// making a combined work based on this library.  Thus, the terms and
// conditions of the GNU General Public License cover the whole
// combination.

#ifndef __CAMERA_H__
#define __CAMERA_H__

#include <SFML/Graphics.hpp>

#include <Metgine/Core/Math.h>
#include <Metgine/Core/Vector2.h>

namespace Metgine
{

namespace Core
{

class Object;

namespace CameraAction
{
    enum CameraAction
    {
        None,
        Move,
        Track
    };
}; // CameraAction

class METGINE_API Camera
{
public:

    // Constructor
    Camera();

    // Moves the camera so that is focuses on a point in world space
    void SetPosition(const Vector2f& point);

    // Sets the view size (should be equal to window size)
    void SetViewSize(int width, int height);

    // Gets the associated view
    const sf::View& GetView() const;

    // Gets the current camera position
    Vector2f GetPosition() const;

    // Gets the world space position on which the camera is focused
    Vector2f GetWorldPosition() const;

    // Gets the world space position associated with a position in screen space
    Vector2f GetWorldPosition(int screenX, int screenY) const;

    // Moves the camera
    virtual void Move(int deltaX, int deltaY, bool internalMove = false);

    // Moves the camera to an object
    virtual void MoveTo(Object*, bool track = false, bool instant = false);

    // Updates the camera
    virtual bool Update(float elapsedTime);

    // Starts tracking an object
    virtual void StartTracking(Object*);

    // Stop tracking the target object
    virtual void StopTracking();

protected:
private:
    Vector2f                           m_position;
    Vector2f                           m_target;
    sf::View                           m_view;
    CameraAction::CameraAction         m_action;
    Object*                            m_targetObject;
};


}; // Graphics
}; // Metgine
#endif // CAMERA_H
